package exception.IllegalArgumentException;


import java.text.SimpleDateFormat;
import java.util.Date;

public class Test3 {

    public static void main(String[] args) {
        Date day = new Date();
        /*正常运行*/
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date = df.format(day);
        System.out.println(date);
        /*报错：IllegalArgumentException: Cannot format given Object as a Date*/
        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM");
        String format = null;
        try {
            format = dateFormat.format(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(format);
    }
}